#include <iostream>

using namespace std;

int n, mark[25], ans;
char mmap[25][25];

void dfs(int s) {
    if (s == n + 1) {
        ans += 1;
        return ;
    }
    for (int i = 1; i <= n; ++i) {
        if (mark[i] == 0 && mmap[s][i]== '1') {
            mark[i] = 1;
            dfs(s + 1);
            mark[i] = 0;
        }
    }

}


int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> &mmap[i][1];
    }
    dfs(1);
    cout << ans << endl;
    return 0;
}